var mongoHelper = require("./mongoHelper");
var uuid = require("node-uuid");

var module = function(callback)
{
	this._id = uuid.v4();
	this.Name = "";
	this.Load = "";
	this.Render = "";
	this.CustomData = [];
	this.Modules = [];

	this.m = new mongoHelper.mongoHelper();


	this.Get = function(query, callback)
	{
		this.m.Get(this, query, callback);
	}
	this.Save = function(callback)
	{
		console.log("Calling Save");
		this.m.Save(this, callback);
	}
	this.Update = function(callback)
	{
		this.m.Update(this, callback);
	}

	this.UpdateSave = function(callback)
	{	
		this.Get
		(
			{ Name: this.Name },
			function(r, s)
			{
				if(s == null)
				{
				
					console.log("Saving");
					r.Save(callback);
					
				}
				else
				{
					console.log("Updating");
					r.Update(callback);
				}
			}
		);
	}
	this.Delete = function(callback)
	{
		this.m.Delete(this, callback);
	}
}
exports.module = module;
